import React, { Fragment } from 'react';
import { Table, Popconfirm, message } from 'antd';
import moment from 'moment';

export default ({ rowSelection, data, handleEditorModal, onChange, handleDelete }) => {
    const columns = [
        {
            title: 'uin',
            dataIndex: 'uin',
        },
        {
            title: 'openid',
            dataIndex: 'openid',
        },
        {
            title: 'aid',
            dataIndex: 'aid',
        },
        {
            title: '备注',
            dataIndex: 'remark'
        },
        {
            title: '操作人',
            dataIndex: 'operator'
        },
        {
            title: 'aegisid',
            dataIndex: 'aegisid'
        },
        {
            title: '更新时间',
            dataIndex: 'updatedAt',
            key: 'updated_at',
            sorter: true,
            render: val => moment(val).format('YYYY-MM-DD')
        },
        {
            title: '操作',
            dataIndex: 'id',
            render: id => {
                return (
                    <Fragment>
                        <span
                            style={{ color: '#1890ff', cursor: 'pointer' }}
                            onClick={() => handleEditorModal(id)}
                        >
                            编辑
                        </span>
                        <span style={{ margin: ' 0 10px', color: '#e8e8e8' }}>|</span>
                        <Popconfirm
                            title="确认删除该条白名单？"
                            onConfirm={() => handleDelete(id)}
                            okText="确定"
                            cancelText="取消"
                        >
                            <span style={{ color: '#f5222d', cursor: 'pointer' }}>删除</span>
                        </Popconfirm>
                    </Fragment>
                )
            }
        }
    ];

    return (
        <Table
            loading={data.loading}
            columns={columns}
            rowSelection={rowSelection}
            dataSource={data.data}
            onChange={onChange}
            rowKey="id"
            pagination={{
                showSizeChanger: true,
                showQuickJumper: true,
                total: data.total,
                current: data.offset / data.limit + 1
            }}
        />
    );
}